/*
 * class.c
 *
 *  Created on: 2013-5-15
 *      Author: xkaying
 */

#include "class.h"
#include "template.h"
#include "declare.h"
#include "function.h"
#include "../common/list.h"

#include <assert.h>
#include <stdlib.h>

struct _class{
		int prority;
		char *name;
		List *super;
		Template *ptemplate;//模板
		//变量列表
		List *pvlist;
		//函数列表
		List *pflist;
};

Class *ClassInit(int prority)
{
	Class *pclass;
	pclass=(Class*)malloc(sizeof(Class));
	pclass->prority=prority;
	pclass->name=0;
	pclass->ptemplate=0;
	pclass->pvlist=0;
	pclass->pflist=0;
	return pclass;
}

void ClassAppendName(Class *pclass ,char *name)
{
	assert(pclass);
	assert(name);
	pclass->name=name;
}

void ClassAppendTemplate(Class *pclass,Template *ptemplate)
{
	assert(pclass);
	assert(ptemplate);
	pclass->ptemplate=ptemplate;
}

void ClassAppendDeclare(Class *pclass,Declare *pdeclare)
{
	assert(pclass);
	assert(pdeclare);
	if(pclass->pvlist==0){
		pclass->pvlist=ListInit();
	}
	ListPush(pclass->pvlist,pdeclare);
}

void ClassAppendFunction(Class *pclass,Function *pdeclare)
{
	assert(pclass);
	assert(pdeclare);
	if(pclass->pflist==0){
		pclass->pflist=ListInit();
	}
	ListPush(pclass->pflist,pdeclare);
}

void ClassAppendSuper(Class *pclass,char *super)
{
	assert(pclass);
	assert(super);
	if(pclass->super==0){
		pclass->super=ListInit();
	}
	ListPush(pclass->super,super);
}

int ClassIsempty(Class *pclass)
{
	assert(pclass);
	if(pclass->pflist||pclass->pvlist){
		return 0;
	}
	return 1;
}

char* ClassName(Class *pclass)
{
	assert(pclass);
	return pclass->name;
}
